﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Imaginecup.sprite;
using Imaginecup.sprite.changeSourceSize;
using imaginecup.util;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Imaginecup.util;
using Imaginecup.util.collision;

namespace Imaginecup.gameState.option
{
    public class VibeController:ISourceInfoClass
    {
        private ISprite m_VibeBtnSprite;

        private EntityInfo m_Info;
        private bool m_bEnable;

        public VibeController()
        {
#if WINDOWS
            m_bEnable = false;
#endif
#if WINDOWS_PHONE
            m_bEnable = VibrateMan.GetVibrateMan().GetEnable();
#endif
            m_Info = new EntityInfo();
            m_Info.mPosition = new Vector2(267, 295);
        }

        public void SetSprite(ISprite sprite)
        {
            m_VibeBtnSprite = sprite;
        }

        public void SetSize( Vector2 size)
        {
            m_Info.mSize = size;
        }

        public EntityInfo GetSourceInfo()
        {
            if( !m_bEnable )
            {
                return new EntityInfo(Vector2.Zero, m_Info.mSize);
            }
            return new EntityInfo(new Vector2(m_Info.mSize.X, 0), m_Info.mSize);
        }

        public void Draw(SpriteBatch sb)
        {
            m_VibeBtnSprite.Draw(sb, m_Info);
        }

        public void Release()
        {
            m_VibeBtnSprite.Release();
            m_VibeBtnSprite = null;
        }

        public void Update(GameTime gameTime)
        {
            IMouseInputHandler input = MouseInputHandler.GetInputHandler();
            if( input.IsOneClickUp() && Collision.CollisionByPoint(m_Info , input.Position))
            {
                m_bEnable = !m_bEnable;
#if WINDOWS_PHONE
                VibrateMan.GetVibrateMan().SetEnable(m_bEnable);
#endif
            }
        }
    }
}
